$(function () {
    $("#login-btn").click(function () {
        // console.log("进入提交表单")
        const email = $("#email").val()
        const password = $("#password").val()
        if (email && !email.trim()) {
            alert("请输入邮箱")
            return
        }

        if (password && !password.trim()) {
            alert("请输入密码")
            return
        }
        const params = {
            email: email,
            password: password,
        }
        // console.log("----------")
        $.ajax(`${baseUrl}/login`, {
            type: "POST",
            data: params,
            success: function (res) {
                // console.log("登录成功：", res)
                const token = res.token
                if (token) {
                    localStorage.setItem("token", token)
                    location.href = "/admin/index.html"
                } else {
                    alert("登录失败！")
                }
            },
            error: function (err) {
                console.log(err)
                alert("密码错误")
            },
        })
    })
})
